home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
4_0
/
HYPERXCM
/
XCMDDIAL.C
< prev
next >
Wrap
Text File
|
1991-10-22
|
6KB
|
203 lines
/*
⌐ 1988 by Gary Bond
All Rights Reserved
Translation to C by Sioux Lacy
Modified by Dick Guertin
Dialog: A HyperCard XCMD that displays a modal dialog box.
The caller can privide the text, font, and location.
Dialog uses dialog box 135 from HyperCard's resource
fork, automatically centering the dialog window within
the card window. Up to 255 characters can be displayed.
Form: Dialog "String to display", Top, Left, "Font Name"
Dialog "String to display", Top, Left
Dialog "String to display", "Font Name"
Dialog "String to display"
Example: Dialog "Display this text", 100, 80, Geneva
Note: Top and Left are integers that specify the upper left point
at which to display the dialog. If you don't supply values
for these, the dialog automatically centers itself within the
card window. The font to display the text in is passed by
name; its size cannot be changed.
*/
#include <MacTypes.h>
#include "HyperXCmd.h"
#include "XCmdUtil.h"
/*- Additional includes for this XCMD -*/
#include <DialogMgr.h>
#include <EventMgr.h>
#include <QuickDraw.h>
/*- Prototypes -*/
pascal void main (XCmdBlockPtr);
int GetLocOfCardWindow (XCmdBlockPtr, Point*);
/*- Constants -*/
#define minParamCount (short) 1
#define maxParamCount (short) 4
#define errorFlag (short) -1
#define edgeCurve (int) 16
#define gapBetween (int) -4
#define lineSize (int) 3
#define boxLeft (int) 68
#define boxTop (int) 113
#define dialogID (int) 135
/*- main code to display text in dialog box -*/
pascal void main (paramPtr)
XCmdBlockPtr paramPtr;
{
short numParams;
Str255 displayStr;
Str255 fontName;
int itemHit;
int offsetLeft;
int offsetTop;
int myFontNum;
int itemType;
DialogPtr myDialogPtr;
Handle tempHandle;
Point cardWindowLoc;
Rect ctlRect;
GrafPtr savePort;
PenState savePen;
/*- Check for valid calling parameters -*/
numParams = GetParamCount(paramPtr,minParamCount, maxParamCount);
if (numParams < 0)
{ Fail(paramPtr, "Form: Dialog \"string\", top, left, font");
return;
}
if ((GetLocOfCardWindow(paramPtr, &cardWindowLoc)) < 0)
{ Fail(paramPtr, "Can't get rect of card window");
return;
}
GetPort (&savePort);
GetPenState (&savePen);
/*- Set defaults for non-passed parms -*/
myFontNum = (int) 0;
offsetLeft = (int) boxLeft;
offsetTop = (int) boxTop;
/*- Get the display parm, we know it exists -*/
HandleToPstr (displayStr, paramPtr->params[0]);
switch (numParams)
{ /*- Make assumptions based on paramCount -*/
case 2: /*- string, font -*/
case 4: /*- string, top, left, font -*/
HandleToPstr (fontName, paramPtr->params[numParams-1]);
GetFNum (fontName, &myFontNum);
if (numParams == 2) break;
case 3: /*- string, top, left -*/
offsetTop = (int) HandleToNum (paramPtr, paramPtr->params[1]);
offsetLeft = (int) HandleToNum (paramPtr, paramPtr->params[2]);
default: break;
}
/*- Set the cursor to the standard arrow -*/
InitCursor();
/*- Make the dialog manager establish the "string" as ^0 -*/
ParamText (displayStr, "", "", "");
/*- Establish the font for the dialog -*/
SetDAFont (myFontNum);
/*------------------------------------------------------------------
* Look in the resource fork for dialogID and return handle if found.
* Make it the uppermost window, which is still invisible right now.
*-----------------------------------------------------------------*/
myDialogPtr = GetNewDialog (dialogID, (Ptr) 0, (WindowPtr) -1);
/*----------------------------------------------------------------
* Move the dialog to its correct screen position before showing it.
* If the user hasn't supplied a location, center the dialog within
* the card window. Then make the dialog the visible active window.
*---------------------------------------------------------------*/
MoveWindow (myDialogPtr, offsetLeft + cardWindowLoc.h,
offsetTop + cardWindowLoc.v, TRUE);
ShowWindow (myDialogPtr);
/*----------------------------------------------------------------
* Make the dialog the current port and make the OK button the
* default by drawing a 3-pixel line around it. Use the constant
* "OK" for the item number when getting the rect.
*---------------------------------------------------------------*/
SetPort (myDialogPtr);
PenSize (lineSize, lineSize);
GetDItem (myDialogPtr, OK, &itemType, &tempHandle, &ctlRect);
InsetRect (&ctlRect, gapBetween, gapBetween);
FrameRoundRect (&ctlRect, edgeCurve, edgeCurve);
/*----------------------------------------------------------------
* Before we make the dialog active, flush events so pending key
* and mouse events won't put the dialog away too early. Once active,
* Once active, test for a click of the "OK" button.
*---------------------------------------------------------------*/
FlushEvents ((int) everyEvent, (int) 0);
do /*- wait for "OK" -*/
{ ModalDialog ((Ptr) 0, &itemHit);
} while (itemHit != OK);
/*----------------------------------------------------------------
* We are done. The user has clicked the OK button, so now it's
* time to clean up, restore the port and penstate.
*---------------------------------------------------------------*/
DisposDialog (myDialogPtr);
SetDAFont (0); /*- reset to system font -*/
SetPort (savePort);
SetPenState (&savePen);
return; /*- Back to HyperCard -*/
} /*- proc-end: main -*/
int GetLocOfCardWindow (paramPtr, loc)
XCmdBlockPtr paramPtr;
Point *loc;
{ /*- return error code indicating success/failure -*/
Handle hndl;
char *str;
str = "\pitem 1 of rect of card window";
hndl = EvalExpr(paramPtr, (StringPtr) str);
if (paramPtr->result == noErr)
{ loc->h = HandleToNum(paramPtr, hndl);
DisposHandle(hndl);
str = "\pitem 2 of rect of card window";
hndl = EvalExpr(paramPtr, (StringPtr) str);
if (paramPtr->result == noErr)
{ loc->v = HandleToNum(paramPtr, hndl);
DisposHandle(hndl);
return(noErr);
}
}
return ((int) errorFlag);
} /*- proc-end: GetLocOfCardWindow -*/